package com.docking.heylo.service.impl;

import com.docking.heylo.dao.entity.AppVersion;
import com.docking.heylo.dao.entity.AppVersionExample;
import com.docking.heylo.dao.mapper.AppVersionMapper;
import com.docking.heylo.service.IAppVersionService;
import com.docking.heylo.web.dto.PageDto;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class AppVersionServiceImpl implements IAppVersionService {

    @Resource
    private AppVersionMapper appVersionMapper;


    @Override
    public PageInfo<AppVersion> list(PageDto page) {
        PageHelper.startPage(page.getPageNumber(), page.getPageSize());
        PageHelper.orderBy(" create_by desc ");
        return new PageInfo<>(appVersionMapper.selectByExample(new AppVersionExample()));
    }


    @Override
    public void push(AppVersion version) {
        version.setCreateAt(new Date());
        version.setState(0);
        appVersionMapper.insertSelective(version);
    }


    @Override
    public void release(AppVersion version) {
        appVersionMapper.updateByPrimaryKeySelective(new AppVersion(){{
            setId(version.getId());
            setState(1);
        }});
    }



}
